import socket
import time
import thread
import threading
from Tkinter import *
import tkFileDialog
def main():
  finestra=Tk()
  finestra.title("Lan Sharer")
  finestra.minsize(300,300)
  finestra.maxsize(300,300)
  cornice=Frame(finestra)
  cornice.pack()
  B1=Button(cornice,text="Start Server",borderwidth=1,command=PB1)
  st=StringVar()
  txt=Entry(textvariable=st,width=30)
  B2=Button(cornice,text="Send File",borderwidth=1,command=PB2)
  B1.pack()
  txt.pack()
  B2.pack()
  finestra.mainloop()
def PB1():
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  s.connect(('google.com', 0))
  ip=s.getsockname()[0]
  lab=Label(text="Put this adress when requested from client: ")
  lab1=Label(text=ip)
  lab.pack()
  lab1.pack()
  b="1"
  b=tuple(b)
  time.sleep(1)
  def serve(x):
    import server
  thread.start_new_thread(serve,b)
def PB2():
  addr=st.get()
  a=tkFileDialog.askopenfilename()
  getfile=open(a,"r")
  fil=getfile.read()
  s=socket.socket()
  s.connect((addr,48364))
  s.send(fil+"\r\n")
  s.close()
main()
